#!/usr/bin/ksh
#**********************************************************************
#                                                                     *
# LPPBUILD_MAKE_SIZES                                                 *
#                                                                     *
# The lpp_name file must include a list of the size requirements      *
# of any directory which is to contain installed files. The full      *
# path name of the target directory should be followed by its size    *
# requirement in 512 byte blocks.                                     *
#                                                                     *
# We achieve this for the given file system by using the find command *
# to list all the actual files (i.e. not directories.). The base      *
# directory names are stripped from these to give us a list of        *
# directory names which do actually contain files (and are not just   *
# empty directories making up a path). This is passed through sort -u *
# to remove duplicates before being given one by one to a du -s to    *
# give us the space requirement for each directory which is to receive*
# files as part of the install. We use awk to remove the leading .    *
# from the output names (to make the directory name absolute) and     *
# also to reorder the du -s output to be name then size, rather than  *
# the reverse.                                                        *
#                                                                     *
# Incoming parameters are as follows:                                 *
#                                                                     *
# $1 - The name of the root directory to process                      *
#                                                                     *
# The output is a series of records written to stdout which are in    *
# the form required for the lpp_name file.                            *
#                                                                     *
# Note the need for special processing of the root directory itself   *
# ("./") which gets shortened by the dirname command to just "."      *
#                                                                     *
#**********************************************************************

restore=`pwd`                          # save current directory name
cd $1                                  # go to the product root
for file in `find . ! -type d -exec dirname {} \; | sort -u`; do
  if [[ $file = "." ]]; then           # have we files in root directory?
    file="./";                         # change "." to "./" if so
  fi                                   # end of worrying about "./"
  du -s $file | awk '{print substr($2,2) " " $1}' # create required output
done                                   # end of outputting details
cd $restore                            # go back to original directory

